
#import "PywResourceUtils.h"
#import <ifaddrs.h>
#import <arpa/inet.h>
#include <string>
#include <iostream>

@interface PywResourceUtils() {
    NSBundle *bundle;
}

@end

@implementation PywResourceUtils

+ (PywResourceUtils *)manger
{
    static id manger = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manger = [[PywResourceUtils alloc] init];
    });
    return manger;
}

- (id)init {
    self = [super init];
    if (self) {

        
        NSBundle *imageBundle = [NSBundle bundleForClass:[PywResourceUtils class]];
        NSURL *url = [imageBundle URLForResource:BundleName withExtension:@"bundle"];
        bundle = [NSBundle bundleWithURL:url];
//        NSString *bundlePath = [[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:BundleName];
//        bundle = [NSBundle bundleWithPath:bundlePath];
        
    }
    return self;
}



- (UIImage *)image:(NSString *)name {
    return [self image:name type:@"png"];
}

- (UIImage *)image:(NSString *)name type:(NSString *)type {
    UIImage *img = [UIImage imageWithContentsOfFile:[bundle pathForResource:[NSString stringWithFormat:@"%@@2x",name] ofType:type]];
    if(!img) img = [UIImage imageWithContentsOfFile:[bundle pathForResource:[NSString stringWithFormat:@"%@@3x",name] ofType:type]];
    return img;
}

- (NSString *)html:(NSString *)name baseURL:(NSURL **)baseURL {
    NSString *filePath = [bundle pathForResource:name ofType:@"html"];
    *baseURL = [NSURL URLWithString:filePath];
    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    return htmlString;
}

- (NSData *)file:(NSString *)name type:(NSString *)type {
    NSString *filePath = [bundle pathForResource:name ofType:type];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    return data;
}


- (id)anyObjct:(NSString *)name type:(NSString *)type
{
    id obj = [bundle URLForResource:name withExtension:type];
    return obj;
}

- (NSString *)getLang:(NSString *)key {
    return NSLocalizedStringFromTableInBundle(key, nil, bundle, nil);
}



@end
